<{extend name="public/layout"}>


<{block name="content"}>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>系统设置</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="<{:url('/admin/index/index')}>">首页</a></li>
                        <li class="breadcrumb-item"><a href="#">定时任务管理</a></li>
                        <li class="breadcrumb-item active">任务列表</li>
                    </ol>
                </div>
            </div>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-header">
                    <form action="<{:url()}>">
                        <div class="form-row ">

                            <div class="col-auto">
                                <select name="status" class="form-control " >
                                    <option  value="">全部状态</option>
                                    <option <{if null !== $Request.param.status &&$Request.param.status=='1'}>selected<{/if}>  value="1">已禁用</option>
                                    <option <{if null !== $Request.param.status &&$Request.param.status=='0'}>selected<{/if}> value="0">启用中</option>

                                </select>
                            </div>

                            <div class="col-auto">

                                <input name="keyword" type="text" class="form-control " placeholder="任务名称" value="">
                            </div>

                            <div class="col-auto">
                                <button type="submit" class="btn btn-primary mb-2 "><i class="fas fa-search"></i></button>
                                <a  href="<{:url('index')}>"  class="btn btn-default mb-2 bs-left-30" title="重置"><i class="fas fa-history"></i></a>

                            </div>
                        </div>
                    </form>
                </div>

                <div class="card-body">
                    <a href="<{:url('form')}>"  class="btn btn-success">新增</a>
                    <div class="alert alert-warning alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-ban"></i> 提示!</h5>
                        目前定时任务功能暂不支持，请手动添加到自己的服务器，下面是系统的任务接口地址。
                        <ul>
                            <li><b>自动收货：</b>域名<{:url('api/mall.order/auto_receive',null,'html',true)}></li>
                            <li><b>支付超时取消：</b>域名<{:url('api/mall.order/auto_cancel',null,'html',true)}></li>
                            <li><b>队列任务：</b>域名<{:url('api/timer.queue/excute',null,'html',true)}></li>
                        </ul>
                    </div>

                </div>

                <table id="my_table" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>任务名称</th>
                        <th>任务类型</th>
                        <th>状态</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <{if !empty($data)}>
                    <{foreach $data as $item}>
                    <tr>
                        <td><{$item.id}></td>
                        <td>
                            <{$item.name}>
                        </td>
                        <td>
                            <{if $item.do_type=='url'}>
                            <span class="bs-blue-2">访问URL</span>
                            <{else}>
                            <span class="bs-green">其它方式</span>
                            <{/if}>
                        </td>
                        <td>
                            <{if $item.status==0}>
                            <span class="bs-grey">已关闭</span>
                            <{else}>
                            <span class="bs-green">启用中</span>
                            <{/if}>
                        </td>

                        <td>
                            添加：<{$item.add_time}> <br>
                            更新：<{$item.up_time}>
                        </td>
                        <td>

                            <a class="btn  btn-outline-dark btn-xs" title="编辑" href="<{:url('form',['id'=>$item.id])}>" >编辑</a>

                            <{if $item.status=='0'}>
                            <span class="btn  btn-success btn-xs set-status" onclick="set_status(this)" data-id="<{$item.id}>"  title="开启">开启</span>
                            <{else}>
                            <span class="btn  btn-warning btn-xs set-status" onclick="set_status(this)" data-id="<{$item.id}>"   title="关闭">关闭</span>
                            <{/if}>
                            <span class="btn  btn-danger btn-xs set-status" onclick="del(this)" data-id="<{$item.id}>"   title="删除">删除</span>
                        </td>

                    </tr>
                    <{/foreach}>
                    <{/if}>



                    </tbody>
                    <tfoot>


                    </tfoot>
                </table>
            </div>
            <div class="card-footer">
                <{$page?$page->render():''}>
            </div>

        </div>
    </section>




</div>
<{/block}>
<{block name="script"}>
<script>

    function set_status(obj){
        var id = $(obj).data('id');
        layer.confirm('确定要修改状态吗',{title:'设置状态确认',btn:['确定','再想想']},function (index) {
            sendData("<{:url('tasks_action')}>",{id:id,ac:'status'},function (res) {
                if (res.code==0){
                    location.reload()
                    layer.close(index)
                }
            })

        })
    }
    function del(obj){
        var id = $(obj).data('id');
        layer.confirm('确定要删除吗',{title:'删除确认',btn:['确定','点错了']},function (index) {
            sendData("<{:url('tasks_action')}>",{id:id,ac:'del'},function (res) {
                if (res.code==0){
                    $(obj).parent('td').parent('tr').remove()
                    layer.close(index)
                }
            })

        })
    }

    $(function () {


        $("#my_table").DataTable({
            "ordering": false,//禁用排序
            "responsive": true,
            "lengthChange": false,
            "autoWidth": false,
            //"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
            // "pageLength": 10,         //初始化显示几条数据
            //serverSide: true, // use local process instead of server
            // bFilter: true, // show top right search input box.
            bPaginate: false,//是否开启分页
            //iDisplayLength: 10, //默认显示的记录数
            bInfo: false,//是否显示页脚信息，DataTables插件左下角显示记录数
        }).buttons().container().appendTo('#my_table_wrapper .col-md-6:eq(0)');

    });
</script>
<{/block}>

